//
//  ShareView.m
//  dzm
//
//  Created by dzmmac on 14-11-10.
//  Copyright (c) 2014年 dzmmac. All rights reserved.
//

#import "ShareView.h"
#import "AppDelegate.h"
#import "AppConfig.h"
#import "WXApi.h"
#import "UIView+Additions.h"
#import "UIScreen+Frame.h"
#import "AppColorConfig.h"
@implementation ShareView
{
    UIWindow *window;
}

+ (ShareView *)sharedManager;
{
    static dispatch_once_t pred = 0;
    __strong static id _sharedObject = nil;
    dispatch_once(&pred, ^{
        _sharedObject = [[self alloc] init];
    });
    return _sharedObject;
}

- (id)init
{
    NSArray *array = [[NSBundle mainBundle ] loadNibNamed:@"ShareView" owner:self options:nil];
    self = array[0];
    self.frame = [UIScreen bounds];


    CGFloat layoutSpace = ([UIScreen width] - (57*4))/5;
    self.weChatLeftSpace.constant = layoutSpace;
    self.wechatTimeLineLeftSpace.constant = layoutSpace;
    self.QQLeftSpace.constant = layoutSpace;
    self.sinaLeftSpace.constant = layoutSpace;

    
    self.cancelBtn.layer.cornerRadius = 6;
    self.cancelBtn.layer.borderColor = GLOBLE_ORANGE_COLOR.CGColor;
    self.cancelBtn.layer.borderWidth = 0.45;
    
    return [super init];
}

- (IBAction)tapAction:(UITapGestureRecognizer *)sender
{
    __weak ShareView *weakSelf = self;
    [UIView animateWithDuration:0.2 animations:^{
        weakSelf.bg.frame = CGRectMake(0, [UIScreen height], [UIScreen width], self.bg.frame.size.height);
        weakSelf.bgView.alpha = 0;
    } completion:^(BOOL finished) {
        [weakSelf removeFromSuperview];
    }];
}

- (IBAction)cancelBtnAction:(UIButton *)sender {
    [self hidden];
}

- (IBAction)btnAction:(UIButton *)sender {
    
    [self.delegate btnClicked:sender];
    [self hidden];
}

-(void)show
{
    self.bgView.alpha = 0;
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    [app.window addSubview:self];
    
    self.bg.frame = CGRectMake(0, [UIScreen height],  [UIScreen width], self.bg.frame.size.height);
    __weak ShareView *weakSelf = self;
    [UIView animateWithDuration:0.2 animations:^{
        weakSelf.bgView.alpha = 0.4;
        weakSelf.bg.frame = CGRectMake(0, [UIScreen height] - self.bg.frame.size.height, [UIScreen width], self.bg.frame.size.height);
    }];
}

-(void)hidden
{
    __weak ShareView *weakSelf = self;
    [UIView animateWithDuration:0.2 animations:^{
        weakSelf.bg.frame = CGRectMake(0, [UIScreen height], [UIScreen width], self.bg.frame.size.height);
        weakSelf.bgView.alpha = 0;
    } completion:^(BOOL finished) {
        [weakSelf removeFromSuperview];
    }];
}
@end
